///geo Module API Module definitions
//

#ifndef GEO_API_MODULE_INC
#define GEO_API_MODULE_INC

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "geo.h"

#define GEO_API_Error unsigned int
#define     geo_API_fault_report() \
    sprintf((char *)geo_buff, "{%s:%s:err=%d:line=%d}", __FILE__, __FUNCTION__, err_no, __LINE__); \
    geo_api_fault.clear(); \
    geo_api_fault = (char *)geo_buff; \
    error = fmaa.fmaa_client_send_report(geo_api_fault, fma_error_report); \
    cout << geo_api_fault << "-> FMA response = " << error << endl;

#define     geo_API_fault_report_unit_test() \
    sprintf((char *)geo_buff, "{%s:%s:err=%d:line=%d}", __FILE__, __FUNCTION__, err_no, __LINE__); \
    geo_api_fault.clear(); \
    geo_api_fault = (char *)geo_buff; \
    error = fmaa.fmaa_client_send_report(geo_api_fault, fma_unit_test_report); \
    cout << geo_api_fault << "-> FMA response = " << error << endl;

using namespace std;

typedef enum egeoAPI_MsgTypes {

	GEO_API_RESET_HW = 0x00ff,
	GEO_API_GET_HW_STATUS,
	GEO_API_READ,
	GEO_API_WRITE,
	NUM_GEO_MSG_TYPES

}type_egeoAPI_MsgTypes;

typedef enum egeoAPI_ErrorTypes {

	GEO_API_NO_ERROR = 0,
	GEO_API_RESET_HW_ERROR,
	GEO_API_GET_HW_STATUS_ERROR,
	GEO_API_READ_ERROR,
	GEO_API_WRITE_ERROR,
	NUM_GEO_ERROR_TYPES

}type_egeoAPI_ErrorTypes;


class Cgeo_API : public Cgeo
{
public:

    Cgeo_API();
    ~Cgeo_API();

    unsigned int Process_Module_API_Request(short API_id);
    unsigned int Process_Module_API_Request(short API_id, unsigned char addr, unsigned char *buf, int nbytes);

    GEO_API_Error Send_API_Request(short API_id);
    GEO_API_Error Send_API_Response(short API_id);

    unsigned char geo_buff[8192];
protected:

private:
    ///Error handling functions
    void HandleHWFault(int err_no);
    void HandleReadHWError(int err_no);
    void HandleWriteHWError(int err_no);
    void HandleResetHWError(int err_no);
    void HandleResetHWFault(int err_no);
    void HandleGetHWStatusError(int err_no);
    void HandleUnknownAPIRequest(int error);

    egeoStatus geo_hw_status;
    GEO_API_Error geo_error;
    GEO_API_Error geo_API_error;
    string geo_api_fault;
    size_t error;

};
#endif

